package com.itheima.tween;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class MainActivity extends Activity {
    private ImageView tweenIV;

	private int height;
    
   public    static final  String TAG="MainActivity";

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        tweenIV = (ImageView) findViewById(R.id.tweenIV);
         height = tweenIV.getDrawable().getIntrinsicHeight();
        Log.i(TAG, height+"");
    }
    
    public void onClick(View view) {
    	Animation anim = null;
    	switch (view.getId()) {
			case R.id.alphaBT:
				anim = AnimationUtils.loadAnimation(this, R.anim.alpha);	// 获取透明动画的XML配置
				break;
			case R.id.scaleBT:
				anim = AnimationUtils.loadAnimation(this, R.anim.scale);
				break;
			case R.id.traslateBT:
//				anim = AnimationUtils.loadAnimation(this, R.anim.translate);
				
				anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
						Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
				anim.setDuration(500);
				anim.setInterpolator(new LinearInterpolator());
				anim.setFillAfter(true);
				break;
			case R.id.rotateBT:
				anim = AnimationUtils.loadAnimation(this, R.anim.rotate);
				break;
			case R.id.allBT:
				anim = AnimationUtils.loadAnimation(this, R.anim.all);
				break;
				
			case R.id.otherBT:
				anim = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
						Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f);
//				anim = AnimationUtils.loadAnimation(this, R.anim.translate_out);
				anim.setDuration(500);
				anim.setFillAfter(true);
				anim.setInterpolator(new LinearInterpolator ());
				break;
				
		}
    	tweenIV.startAnimation(anim);		// 应用动画
    }
}